layui.use(['form', 'admin', 'ax','laydate','upload','formSelects'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var upload = layui.upload;
    var laydate = layui.laydate;


    var enumAjax = new $ax(Feng.ctxPath + "/enums/sceneTypes");
    var enumRes = enumAjax.start();
    var projects = enumRes.data;
    var html = "";
    for(var key in projects){
        html += '<option value="'+key+'">'+projects[key]+'</option>'
    }
    $("#type").append(html);
    form.render('select');
    //普通图片上传
    upload.render({
        elem: '#img'
        ,url: Feng.ctxPath + '/system/upload'
        ,done: function(res){
             if(res.success){
                 $('#imgImgPreview').attr('src', Feng.cdn + res.data.finalName);
                 $("input[name=img]").val(res.data.finalName);
                 Feng.success("操作成功！");
             }else{
                 Feng.error("操作失败！" + data.message)
             }
        }
        ,error: function(){
            Feng.error("操作失败！");
        }
    });
//普通图片上传
    upload.render({
        elem: '#imgSel'
        ,url: Feng.ctxPath + '/system/upload'
        ,done: function(res){
            if(res.success){
                $('#imgSelImgPreview').attr('src', Feng.cdn + res.data.finalName);
                $("input[name=imgSel]").val(res.data.finalName);
                Feng.success("操作成功！");
            }else{
                Feng.error("操作失败！" + data.message)
            }
        }
        ,error: function(){
            Feng.error("操作失败！");
        }
    });

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/nanScene/addItem", function (data) {
            if(data.success){
                 Feng.success("操作成功！");
                        window.location.href = Feng.ctxPath + '/nanScene'
            }else{
                Feng.error("操作失败！" + data.message)
            }
        }, function (data) {
            Feng.error("操作失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    $('#cancel').click(function(){
        window.location.href = Feng.ctxPath + '/nanScene'
    });

});
